package com.atguigu.dao.impl;

import com.atguigu.dao.MainTaskDao;
import com.atguigu.pojo.MainTask;

import java.util.List;

public class MainTaskDaoImpl extends BaseDao implements MainTaskDao {
    @Override
    public int addMainTask(MainTask mainTask) {
        System.out.println("MainTaskDaoImpl 程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_mainTask(`id`,`deployServiceModuleId`,`deployGoalId`,`name`,`status`,`lastId`) values(?,?,?,?,?,?);";
            return update(sql,mainTask.getId(),mainTask.getDeployServiceModuleId(),mainTask.getDeployGoalId(),mainTask.getName(),
                    mainTask.getStatus(),mainTask.getLastId());
    }

    @Override
    public int deleteMainTaskById(String id) {
        String sql="delete from t_mainTask where id=?";
        return update(sql,id);
    }

    @Override
    public int updateMainTask(MainTask mainTask) {
        String sql="update t_mainTask set `id`=?,`deployServiceModuleId`=?,`deployGoalId`=?,`name`=?,`status`=?,`lastId`=? where id=?";
        return update(sql,mainTask.getId(),
                mainTask.getDeployServiceModuleId(),mainTask.getDeployGoalId(),mainTask.getName(),mainTask.getStatus(),mainTask.getLastId(),
                mainTask.getId());
    }

    @Override
    public MainTask queryMainTaskById(String id) {
        String sql ="select `id`,`deployServiceModuleId`,`deployGoalId`,`name`,`status`,`lastId` from t_mainTask where id=?";
        return queryForOne(MainTask.class,sql,id);
    }
    @Override
    public MainTask queryMainTaskByLastId(String lastId) {
        String sql ="select `id`,`deployServiceModuleId`,`deployGoalId`,`name`,`status`,`lastId` from t_mainTask where lastId=?";
        return queryForOne(MainTask.class,sql,lastId);
    }

    @Override
    public List<MainTask> queryMainTasks() {
        String sql ="select `id`,`deployServiceModuleId`,`deployGoalId`,`name`,`status`,`lastId`  from t_mainTask";
        return queryForList(MainTask.class,sql);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from t_mainTask";
        Number serverCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverCount.intValue();
    }

    @Override
    public List<MainTask> queryForPageItems(Integer begin, Integer pageSize) {
        String sql ="select `id`,`deployServiceModuleId`,`deployGoalId`,`name`,`status`,`lastId`  from t_mainTask limit ?,?";
        return queryForList(MainTask.class,sql,begin,pageSize);

    }
}
